package ru.infosystem.client;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import ru.infosystem.client.BDConnection;

/**
 *
 * @author akoshi
 */

public class BDConnectionFactory {
    
    private BDConnectionFactory() { }
    
    public static BDConnection getDBConnection(String innetAddr, int portNumber) {
        
        BDConnection  connection = null;
          
        try {

            Socket socket = new Socket(innetAddr, portNumber); 

            InputStream  in  = socket.getInputStream();   
            OutputStream out = socket.getOutputStream();
            
            connection = new BDConnection(socket, in, out);
            
        } catch (UnknownHostException e) {
            
              System.err.println("Don't know about host: " + innetAddr);

        } catch (IOException e) {
            
              System.err.println("Couldn't get I/O for the connection to: " +   
                                      innetAddr);
        } finally {
            
            return connection;
        }
    }    
}
